package com.guofen.controller.sjq;

import com.guofen.pojo.SjqSolidliquidProduceElectricity;
import com.guofen.pojo.SjqSolidliquidProduceEquipmentRunning;
import com.guofen.service.sjq.SjqSolidliquidProduceEquipmentRunningService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/sjq/solidliquidProduceEquipmentRunning")
@Controller
@Api(tags = "SjqSolidliquidProduceEquipmentRunningController", description = "固液分离 生产现场 记录表（设备运行）")
public class SjqSolidliquidProduceEquipmentRunningController {

    @Autowired
    private SjqSolidliquidProduceEquipmentRunningService sjqSolidliquidProduceEquipmentRunningService;

    @ApiOperation("添加开机时间（操作人）")
    @RequestMapping(value = "/addOnTime", method = RequestMethod.POST)
    @ResponseBody
    public Result addOnTime(@ApiParam(name = "equipment_name", value = "设备名称", required = true) @RequestParam String equipment_name,
                            @ApiParam(name = "operator", value = "操作人", required = true) @RequestParam String operator){
        if (sjqSolidliquidProduceEquipmentRunningService.addOnTime(equipment_name, operator))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("添加关机时间（操作人）")
    @RequestMapping(value = "/addOffTime", method = RequestMethod.POST)
    @ResponseBody
    public Result addOffTime(@ApiParam(name = "equipment_name", value = "设备名称", required = true) @RequestParam String equipment_name,
                             @ApiParam(name = "operator", value = "操作人", required = true) @RequestParam String operator){
        if (sjqSolidliquidProduceEquipmentRunningService.addOffTime(equipment_name, operator))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("添加备注（操作人）")
    @RequestMapping(value = "/addRemarks", method = RequestMethod.POST)
    @ResponseBody
    public Result addRemarks(@ApiParam(name = "equipment_name", value = "设备名称", required = true) @RequestParam String equipment_name,
                             @ApiParam(name = "remarks", value = "备注", required = true) @RequestParam String remarks,
                             @ApiParam(name = "operator", value = "操作人", required = true) @RequestParam String operator){
        if (sjqSolidliquidProduceEquipmentRunningService.addRemarks(equipment_name, remarks, operator))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("添加记录（检查人）")
    @RequestMapping(value = "/addExaminationalForm", method = RequestMethod.POST)
    @ResponseBody
    public Result addExaminationalForm(@ApiParam(name = "equipment_name", value = "设备名称", required = true) @RequestParam String equipment_name,
                                       @ApiParam(name = "remarks", value = "备注", required = true) @RequestParam String remarks,
                                       @ApiParam(name = "examiner", value = "检查人", required = true) @RequestParam String examiner){
        if (sjqSolidliquidProduceEquipmentRunningService.addExaminationalForm(equipment_name, remarks, examiner))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("获取当天设备运行记录")
    @RequestMapping(value = "/getListOnTheDay", method = RequestMethod.GET)
    @ResponseBody
    public Result getListOnTheDay(){
        return ResultGenerator.genSuccessResult(sjqSolidliquidProduceEquipmentRunningService.getListOnTheDay());
    }

    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqSolidliquidProduceEquipmentRunningService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="id",required=true) @RequestParam(required = true) Integer id,
                         @ApiParam(name="date",value="date",required=false) @RequestParam(required = false) String date,
                         @ApiParam(name="shift",value="shift",required=false) @RequestParam(required = false) String shift,
                         @ApiParam(name="equipment_name",value="equipment_name",required=false) @RequestParam(required = false) String equipment_name,
                         @ApiParam(name="on_time1",value="on_time1",required=false) @RequestParam(required = false) String on_time1,
                         @ApiParam(name="off_time1",value="off_time1",required=false) @RequestParam(required = false) String off_time1,
                         @ApiParam(name="on_time2",value="on_time2",required=false) @RequestParam(required = false) String on_time2,
                         @ApiParam(name="off_time2",value="off_time2",required=false) @RequestParam(required = false) String off_time2,
                         @ApiParam(name="operator",value="operator",required=false) @RequestParam(required = false) String operator,
                         @ApiParam(name="examiner",value="examiner",required=false) @RequestParam(required = false) String examiner,
                         @ApiParam(name="result",value="result",required=false) @RequestParam(required = false) String result,
                         @ApiParam(name="remarks",value="remarks",required=false) @RequestParam(required = false) String remarks

    ) {
        SjqSolidliquidProduceEquipmentRunning record = new SjqSolidliquidProduceEquipmentRunning();
        record.setId(id);
        record.setDate(date);
        record.setShift(shift);
        record.setEquipmentName(equipment_name);
        record.setOnTime1(on_time1);
        record.setOffTime1(off_time1);
        record.setOnTime2(on_time2);
        record.setOffTime2(off_time2);
        record.setOperator(operator);
        record.setExaminer(examiner);
        record.setResult(result);
        record.setRemarks(remarks);

        return ResultGenerator.genSuccessResult(sjqSolidliquidProduceEquipmentRunningService.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间(时间戳：毫秒)",required = false) @RequestParam(required = false) Long startTime,
                         @ApiParam(name="endTime",value="截止时间(时间戳：毫秒)", required = false) @RequestParam(required = false) Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqSolidliquidProduceEquipmentRunningService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqSolidliquidProduceEquipmentRunningService.getByTime(pageSize, currentPage, startTime, endTime));
    }
}
